<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      xmlns:th="http://www.thymeleaf.org"
      layout:decorator="backstage/layout">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>活动管理</title>
</head>

<body>
<div id="content" layout:fragment="content">

<script type="text/javascript">
		function paging(page){
		    $("[name=page]").val(page);
		    $("#searchForm").submit();
		}
        $(function(){
            var options = {
                    currentPage: $("[name=page]").val(),
                    totalPages: $("[name=totalPage]").val(),
                    alignment:"left",
                    itemTexts: function (type, page, current) {
                        switch (type) {
                            case "first":
                                return "首页";
                            case "prev":
                                return "上一页";
                            case "next":
                                return "下一页";
                            case "last":
                                return "末页";
                            case "page":
                                return page;
                        }
                    },
                    pageUrl: function(type,page,current){
                        return "javascript:paging('"+page+"');";
                    }
                }
                $('#example').bootstrapPaginator(options);
            
              $(".btn-danger").click(function(e){
                if(confirm("确定删除吗?")){
                    $.ajax({
                        url:'/activity/delete.json?id='+ e.currentTarget.id,
                        type:'POST',
                        dataType:"json",
                        success:function(date) {
                            if(date.obj){
                                $(".close").click();
                                alert("删除成功！");
                                window.location.href = "/activity/list.htm";
                            }else{
                               	alert("删除有误！");
                               	window.location.href = "/activity/list.htm";
                            }
                        }
                    });
                } 
              }); 
        });     
            
/*             //选中查询前的状态
            $("#userStatus option[value="+$('#status_value').val()+"]").attr("selected", "true"); */
         $(function(){  
            //添加用戶前
            $(".btn-setting").click(function(e){
                $(".error").removeClass().addClass("control-group");
                $(".help-inline").remove();
                $("#add_brandId").val('');
                document.getElementById("add_type1").checked=true;
            });
            
            
            $("#addActivity").validate({
                checkStart : true,
                errorElement: 'span',
                errorClass: 'help-inline',
                focusInvalid: false,
                rules : {
                	brandId : {
                        required: true
                    }
                },
                messages : {
                	brandId : {
                        required : "必须选择！"
                    }
                },
                submitHandler : function(form) {
                    $("#addActivity").ajaxSubmit(function(date,res,me){
                        if(date.suc){
                            alert("保存成功了！");
                            window.location.href = "/activity/list.htm";
                        } else{
                        	alert("保存失败了！"+date.msg);
                        }
                    });
                },
                highlight: function (e) {
                    $(e).closest('.control-group').removeClass('info').addClass('error');
                }
            });
            
            $(".btn-inverse").click(function(e){
                $("#page").attr("value","1");
            });
        });
            
    </script>
    <div class="box-content">
        <div class="row-fluid sortable">
            <div class="box span12">
            
                <h3 class="row-fluid header smaller lighter blue" style="border:none;">
                    <a href="#" class="btn btn-small btn-success btn-setting" data-toggle="modal" data-target="#myModal"><i class="icon-user"></i>新建活动</a>
                    <a href="/brand/brandList.htm" class="btn btn-small btn-success btn-setting" data-toggle="modal" ><i class="icon-user"></i>活动品牌</a>
                </h3>
                
                <form action="/activity/list.htm" method="post" id="searchForm" style="margin-left:10px;">
		            <input type="hidden"  id="page" name="page" th:value="${page.page}" />
		            <input type="hidden"  name="totalPage" th:value="${page.totalPage}" />
		            <input type="hidden" id="myUserId" th:value="${session.myUserId}" />
		           		 活动品牌：<select name="brandId">
			                    <option value="" >--全部--</option>
			                    <option th:each="activityBrand:${activityBrandList}" th:value="${activityBrand.id}" 
			                    		 th:text="${activityBrand.name}" th:selected="${activityBrand.id == page.filter[brandId]}" ></option>
			                 </select>
		           		 
		            	活动名称：<input type="text" class="input-xlarge focused" name="name" th:value="${page.filter[name]}"/>
		            	
		            <input type="submit" class="btn btn-info btn-inverse tpbtn" style="margin-left:10px;" value="搜索"/>				
		        </form>
        
                <div class="box-content" >
                    <table class="table table-striped table-bordered bootstrap-datatable datatable">
                        <thead>
                        <tr >
                            <th style="text-align: center;">序号</th>
                            <th style="text-align: center;">活动名称</th>
                            <th style="text-align: center;">活动状态</th>
                            <th style="text-align: center;">活动品牌</th>
                            <th style="text-align: center;">开始时间</th>
                            <th style="text-align: center;">结束时间</th>
                            <th style="text-align: center;">参与人数</th>
                            <th style="text-align: center;">操作</th>
                        </tr>
                        </thead>
                        <tbody  >
                        <tr th:each="activity,inStat:${page.result}">
                        	<td th:text="${activity.id}" style="text-align: center;"></td>
                            <td th:text="${activity.name}" style="text-align: center;"></td>
                            <td  style="text-align: center;"  >
                              <span th:if="${activity.status == '1'}">开启</span>
                              <span th:if="${activity.status == '2'}">关闭</span>
                            </td>
                            <td th:text="${activity.brandName}" style="text-align: center;"></td>
                            <td th:text="${activity.startTime}" style="text-align: center;"></td>
                            <td th:text="${activity.endTime}" style="text-align: center;"></td>
                            <td th:text="${activity.personNum}" style="text-align: center;"></td>
                            <td style="text-align: center;">
 <!--                                 <a class="deletebtn btn btn-small btn-danger" th:id="${activity.id}" style="width: 26px;">
                                    	删除
                                </a>  -->
                                 <a class="editbtn btn btn-info btn-small" th:href="${'/activity/editHtml.htm?id='+activity.id}" th:id="${activity.id}" style="width: 50px;">
                           				编辑活动
                                </a>
                                <a class="editbtn btn btn-info btn-small" th:id="${activity.id}" style="width: 50px;" th:href="'/activity/export.htm?id='+${activity.id}">
                           				 导出答卷
                                </a>
                                <input type="hidden" th:id="'name-'+${activity.id}" th:value="${activity.name}"/>
	                            <input type="hidden" th:id="'brandId-'+${activity.id}" th:value="${activity.brandId}"/>
	                            <input type="hidden" th:id="'type-'+${activity.id}" th:value="${activity.type}"/>
	                            <input type="hidden" th:id="'status-'+${activity.id}" th:value="${activity.status}"/>
	                            <input type="hidden" th:id="'startTime-'+${activity.id}" th:value="${activity.startTime}"/>
	                            <input type="hidden" th:id="'endTime-'+${activity.id}" th:value="${activity.endTime}"/>
	                            <input type="hidden" th:id="'imgPath-'+${activity.id}" th:value="${activity.imgPath}"/>
	                            <input type="hidden" th:id="'mark-'+${activity.id}" th:value="${activity.mark}"/>
	                            <input type="hidden" th:id="'personNum-'+${activity.id}" th:value="${activity.personNum}"/>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                    <div style="margin-bottom: 0px; margin-left: auto;margin-right: auto">
		                <div id="example" style="margin-bottom:0px"></div>
		            </div>
                </div>
            </div><!--/span-->
        </div><!--/row-->
    </div>
    <div id="myModal" class="modal hide fade in">
        <div class="modal-header">
            <button class="close" data-dismiss="modal" type="button">×</button>
            <h3>新建活动</h3>
        </div>
        <form class="form-horizontal" style="margin: 0" action="/activity/add.json" method="post" id="addActivity" >
            <fieldset>
                <div class="modal-body">
                    <div class="control-group">
                        <label class="control-label">活动品牌：</label>
                        <div class="controls">
                            <select name="brandId" id="add_brandId">
			                    <option value="" >--全部--</option>
			                    <option th:each="activityBrand:${activityBrandList}" th:value="${activityBrand.id}" 
			                    		 th:text="${activityBrand.name}" ></option>
			                 </select>
                        </div>
                    </div>
                    
                    <div class="control-group">
                        <label class="control-label">活动类型：</label>
                        
                        <div class="controls">
                            	<input class="input-xlarge focused"  type="radio" value="1" name="type" id="add_type1" checked="true"/>竞猜问题
                            	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            	<input class="input-xlarge focused"  type="radio" value="2" name="type" id="add_type2"/>问卷活动
                        </div>
                    </div>
                    
                </div>
                <div class="modal-footer">
                    <input type="submit" class="btn btn-primary btn-small" value="保存" />
                    <a href="#" class="btn btn-small" data-dismiss="modal">取消</a>
                </div>
            </fieldset>
        </form>
    </div>
    
</div>
</body>
</html>
